/**
 * uniapp常用交互反馈
 */

// 操作成功提示
function showSuccessToast(title='操作成功', duration=2000) {
	uni.showToast({
		title: title,
		duration: duration,
		image: '../../static/images/success.png',
		icon: 'success'
	})
}

// 操作失败提示
function showErrorToast(title='操作失败', duration=2000) {
	// uni.showToast({
	// 	title: title,
	// 	duration: duration,
	// 	image: '../../static/images/error.png',
	// 	icon: 'none'
	// })
	uni.showModal({
		title: '提示',
		content: title,
		showCancel: false,
		success: function (res) {
			
		}
	});
}

// 操作警告提示
function showWarningToast(title='非法操作', duration=2000) {
	// uni.showToast({
	// 	title: title,
	// 	duration: duration,
	// 	image: '../../static/images/warning.png',
	// 	icon: 'none'
	// })
	uni.showModal({
		title: '提示',
		content: title,
		showCancel: false,
		success: function (res) {
			
		}
	});
}

// 带确定取消按钮的消息提示框
function showModal(title, confirm = () => {}, cancel = () => {}) {
	uni.showModal({
		title: '提示',
		content: title,
		success: function (res) {
			if (res.confirm) {
				confirm()
			} else if (res.cancel) {
				cancel()
			}
		}
	});
}

// 带确定按钮的消息提示框
function showConfirmModal(title, callback = () => {}) {
	uni.showModal({
		title: '提示',
		content: title,
		showCancel: false,
		success: function (res) {
			callback()
		}
	});
}

// 底部弹窗消息提示
function showActionSheet(itemList, callback = () => {}) {
	uni.showActionSheet({
		itemList: itemList,
		success: function (res) {
			callback(res.tapIndex)
		}
	});
}

export default {
	showSuccessToast,
	showErrorToast,
	showWarningToast,
	showModal,
	showConfirmModal,
	showActionSheet
}